﻿using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaLibModel.Business;
using YiMeiJiaLibModel.Business.Dto;
using YiMeiJiaLibModel.Config;
using YiMeiJiaLibModel.Enums;
using YiMeiJiaService.Assembly;
using YiMeiJiaService.IService;
namespace YiMeiJiaApp.Pages.Find
{
    public partial class GLis
    {
        #region 服务组件

        [Inject] private IAcccount _account { get; set; }
        [Inject] private IGoods _goods { get; set; }

        [Inject] protected NavigationManager Navigation { get; set; }

       

        [Inject] protected IJSRuntime JSRuntime { get; set; }
        #endregion



        #region 绑定数据

        public List<GameList> _games { get; set; }
        #endregion



        /// <summary>
        /// 加载事件
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {
            _games = new List<GameList> { };
            _games.Add(new GameList
            {
                name = "五子棋",
                desc = "具体说明",
                path = "/games/FiveInALine-with-AI/index.html" , game_id = 1
            });
   
            _games.Add(new GameList
            {
                name = "魔塔",
                desc = "经典50层",
                path = "/games/Mota-master/index.html",
                game_id = 4
            });
            _games.Add(new GameList
            {
                name = "象棋",
                desc = "经典50层",
                path = "/games/chess-game-master/index.html",
                game_id = 5
            });
            try
            {
                //  var result = await _HttpClient.Action<List<GameList>>("获取游戏列表", null, false,true);
                string msg = "all";
                
            }
            catch (Exception ex)
            {
                throw;
            }
            await base.OnInitializedAsync();
        }

        public async Task ClickGame(int game_id)
        {
            var game = _games.Where(x => x.game_id == game_id).FirstOrDefault();
            if (game != null)
            {
                //  ;
                EvalJs.ExJs().EvalVoid(JSRuntime, $" $('#GameTitle').html('{game.name}')");
                EvalJs.ExJs().EvalVoid(JSRuntime, $"$(\"#gameViews\").attr(\"src\", `{ApiConf.ApiStatic()}/{game.path}`);");
            }
            else
            {
                await EvalJs.ExJs().Toptip(JSRuntime, "找不到对应的游戏地址", EmToptip.error, 5);
                return;
            }

        }

        public   void JiLi()
        {
               EvalJs.ExJs().EvalVoid(JSRuntime, "bingge()");
        }
    }
}
